import { defineConfig, loadEnv  } from 'vite'
import vue from '@vitejs/plugin-vue'
import autoImportPlugin from '@opentiny/unplugin-tiny-vue'
import path from 'path'
export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, 'config')
  return  {
    envDir: 'config',
    plugins: [vue(), autoImportPlugin('vite')],
    resolve: {
      alias: {
        '@': path.resolve(__dirname, 'src'),
        'untils': path.resolve(__dirname, 'src/views/untils'),
      }
    },
    build: { sourcemap: false },
    server: {
      open: true,
      // host: "0.0.0.0",
      port: env.VITE_PORT,
      base: env.VITE_API_BASE_URL,
      proxy: {
        '/api' : {
          target: env.VITE_API_BASE_URL,
          changeOrigin: true,
          // rewrite: (path) => path.replace(/\/api/, '')
        }
      }
    },
  }
})
